package cn.bsuc.crm.controller;


import cn.bsuc.crm.service.PermissionService;
import cn.bsuc.crm.util.Code;
import cn.bsuc.crm.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhuoyuan
 * @since 2022-10-03
 */
@RestController
@RequestMapping("/permission")
@CrossOrigin
public class PermissionController {
    @Autowired
    private PermissionService permissionService;

    //角色授权
    @GetMapping("/savePermission")
    public Result savePermission(Integer roleId, Integer[] moduleIds){
        int i = permissionService.savePermission(roleId, moduleIds);
        if (i==1){
            return Result.ok();
        }else if (i==0){
            return  Result.fail(Code.ERROR,"授权失败");
        }else {
            return Result.fail(Code.SYSTEM_ERR,"系统出错");
        }
    }
}

